package com.interview.javabase.aggregate.set;

import java.util.HashMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: zsg
 * @description:
 * @date: 2019/6/30 11:59
 * @modified:
 */
public class Demo1 implements Comparable<Demo1> {

    private String name;

    private int age;

    private int score;

    public String getName() {
        return name;
    }

    public Demo1 setName(String name) {
        this.name = name;
        return this;
    }

    public int getAge() {
        return age;
    }

    public Demo1 setAge(int age) {
        this.age = age;
        return this;
    }

    public int getScore() {
        return score;
    }

    public Demo1 setScore(int score) {
        this.score = score;
        return this;
    }

    @Override
    public int compareTo(Demo1 demo1) {

        if (name.compareTo(demo1.name)>0){
            return 1;
        }

        if (name.compareTo(demo1.name)<0){
            return -1;
        }

        if (age > demo1.age){
            return 1;
        }

        if (age < demo1.age){
            return -1;
        }
        return 0;
    }

    @Override
    public String toString() {
        return "Demo1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    public static void main(String[] args) {
        TreeSet<Demo1> treeSet = new TreeSet<Demo1>();
        treeSet.add(new Demo1().setAge(10).setName("A").setScore(98));
        treeSet.add(new Demo1().setAge(11).setName("B").setScore(25));
        treeSet.add(new Demo1().setAge(8).setName("C").setScore(58));
        treeSet.add(new Demo1().setAge(1).setName("D").setScore(12));
        treeSet.add(new Demo1().setAge(6).setName("E").setScore(62));
        treeSet.add(new Demo1().setAge(36).setName("F").setScore(19));
        treeSet.add(new Demo1().setAge(12).setName("F").setScore(19));

        treeSet.forEach(demo1 -> {
            System.out.println(demo1);
        });
    }
}
